#!/bin/bash

GIT_ACTIVE=${1:-"dev"}
ACTIVE=${2:-"dev"}
APP_NAME=flexui-server.jar
LOG_NAME=$APP_NAME-all.log
APP_PORT=8080
OBJECT_PATH=/home/www/workspace/flexui/flexui-server
echo "=====开始执行======$GIT_ACTIVE $ACTIVE ..  $APP_NAME .. $LOG_NAME .. $APP_PORT"
cd $OBJECT_PATH || exit
mvn clean package -Dmaven.test.skip=true
cp ${OBJECT_PATH}/target/$APP_NAME ./
ps -ef | grep $APP_NAME | grep -v grep
if [ $? -ne 0 ]
then
nohup java  -jar -Xms512m -Xmx1024m $APP_NAME --server.port=$APP_PORT --spring.profiles.active="$ACTIVE"  >> ./logs/$LOG_NAME 2>&1 &
echo $APP_NAME "start success"
else
ps -ef | grep $APP_NAME | grep -v grep |awk '{print $2}' |xargs kill -9
echo $APP_NAME "stop success"
nohup java  -jar -Xms512m -Xmx1024m $APP_NAME --server.port=$APP_PORT --spring.profiles.active="$ACTIVE"  >> ./logs/$LOG_NAME 2>&1 &
echo $APP_NAME "start success"
fi
echo "=====执行结束======"


